'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { user, upload } = controller;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 登录
  if (enableRSAChecker) {
    router.post('/api/user/login', sign(), user.login);
  } else {
    router.post('/api/user/login', user.login);
  }
  router.post('/api/user/editPassword', user.editPassword);

  // 头像上传
  router.post('/upload/avatar', upload.avatar);
  // 老师
  router.get('/api/teacher/list', controller.teacher.allList);
  router.resources('teacher', '/api/teacher', ...checks, controller.teacher);
  // 学生
  router.post('/api/student/updateStatus', controller.student.updateStatus)
  router.get('/api/student/list', controller.student.allList);
  router.resources('student', '/api/student', ...checks, controller.student);

  // 班级
  router.get('/api/class/list', controller.class.allList);
  router.resources('class', '/api/class', ...checks, controller.class);


  // 院系
  router.get('/api/school/list', controller.school.allList);
  router.resources('school', '/api/school', ...checks, controller.school);

  // 课程类型
  router.get('/api/category/list', controller.category.allList);
  router.resources('category', '/api/category', ...checks, controller.category);

  // 课程
  router.get('/api/course/list', controller.course.allList);
  router.resources('course', '/api/course', ...checks, controller.course);
  // 已开课课程
  router.get('/api/course_start/list',...checks, controller.courseStart.allList);
  router.resources('course_start', '/api/course_start', ...checks, controller.courseStart);

  // 学生已选课程
  router.get('/api/course_student/list', controller.courseStudent.allList);
  router.resources('course_student', '/api/course_student', ...checks, controller.courseStudent);
  // 成绩
  router.get('/api/score/list', controller.score.allList);
  router.resources('score', '/api/score', ...checks, controller.score);


  // 考勤
  router.get('/api/day/list', controller.day.allList);
  router.resources('day', '/api/day', ...checks, controller.day);

  // 评价
  router.get('/api/ap/list', controller.ap.allList);
  router.resources('ap', '/api/ap', ...checks, controller.ap);

  // notice
  router.get('/api/notice/list', controller.notice.allList);
  router.resources('notice', '/api/notice', ...checks, controller.notice);

  // calendar
  router.get('/api/calendar/list', controller.calendar.allList);
  router.resources('calendar', '/api/calendar', ...checks, controller.calendar);

  // calendar
  router.get('/api/exam/list', controller.exam.allList);
  router.resources('exam', '/api/exam', ...checks, controller.exam);
};
